home *** CD-ROM | disk | FTP | other *** search
- /**********************************************************
- * Basic Black © 1993 by Mason L. Bliss
- * - version 1.3b5 - 11/6/1993 -
- *
- * This cdev code uses the sample cdev class included with
- * the Think C 5 compiler.
- **********************************************************/
-
- /**********************************************************
- * Version History: (cdev code)
- *
- * 1.2 11/93
- * Added in patch global for menu bar kluge. We now use the
- * Gestalt 'BBlk' selector to determine whether or not the
- * patch has actually been installed.
- *
- * 1.1 7/93
- * Switched over to the object-oriented cdev model included
- * with the Think C 5 compiler. Also, fixed a bug that
- * caused crashes under System 6.
- *
- * 1.0 6/93
- * Converted cdev code from SC.010.EditTextCdev, and added
- * code to modify Basic Black's CNFG resource.
- **********************************************************/
-
- #include <cdev.h>
- #include <GestaltEqu.h>
- #include "BBcdev.h"
- #include "BB.h"
-
-
-
- /**********************************************************
- * BBcdev::Init
- *
- * This method initializes our 'once' counter.
- **********************************************************/
- void BBcdev::Init(void)
- {
- once = false;
- inherited::Init();
- }
-
-
-
- /**********************************************************
- * BBcdev::Idle
- *
- * This is a bloody kludge we have to do because it seems
- * that we don't get activate messages under System 6.
- **********************************************************/
- void BBcdev::Idle(void)
- {
- if (!once)
- Activate();
- }
-
-
-
- /**********************************************************
- * BBcdev::Activate
- *
- * This method reads the values stored in the CNFG
- * resource, and sets the dialog control values
- * accordingly.
- **********************************************************/
- void BBcdev::Activate(void)
- {
- Handle configHandle;
- ControlHandle theControl;
- short controlValue;
- long theLong, width, height;
- Rect box;
- Str255 theString;
-
- once = true; // grumble, grumble
-
- configHandle = GetIndResource('PREF', 1); // get the first 'PREF'
- if (ResError()) {
- Error(cdevResErr);
- return;
- }
-
- /* Load Picture Resources */
- pictHandles[0] = GetResource('PICT', topLeftPict);
- pictHandles[1] = GetResource('PICT', topRightPict);
- pictHandles[2] = GetResource('PICT', botRightPict);
- pictHandles[3] = GetResource('PICT', botLeftPict);
-
- /* get the sleep corner info */
- sleepNowRect = **configHandle;
- GetDItem(dp, lastItem - initDev + sleepNow,
- &controlValue, &theControl, &box);
- SetDItem(dp, lastItem - initDev + sleepNow,
- controlValue, pictHandles[sleepNowRect], &box);
-
- width = ((box.right - box.left) / 2);
- height = ((box.bottom - box.top) / 2);
-
- /* Set up some small rects */
- smallSNRect[0] = box;
- smallSNRect[0].right -= width;
- smallSNRect[0].bottom -= height;
- smallSNRect[1] = box;
- smallSNRect[1].left += width;
- smallSNRect[1].bottom -= height;
- smallSNRect[2] = box;
- smallSNRect[2].left += width;
- smallSNRect[2].top += height;
- smallSNRect[3] = box;
- smallSNRect[3].right -= width;
- smallSNRect[3].top += height;
-
- /* get the wake corner info */
- neverSleepRect = *(*configHandle + 1);
- GetDItem(dp, lastItem - initDev + neverSleep,
- &controlValue, &theControl, &box);
- SetDItem(dp, lastItem - initDev + neverSleep,
- controlValue, pictHandles[neverSleepRect], &box);
-
- width = ((box.right - box.left) / 2);
- height = ((box.bottom - box.top) / 2);
-
- /* Set up more small rects */
- smallNSRect[0] = box;
- smallNSRect[0].right -= width;
- smallNSRect[0].bottom -= height;
- smallNSRect[1] = box;
- smallNSRect[1].left += width;
- smallNSRect[1].bottom -= height;
- smallNSRect[2] = box;
- smallNSRect[2].left += width;
- smallNSRect[2].top += height;
- smallNSRect[3] = box;
- smallNSRect[3].right -= width;
- smallNSRect[3].top += height;
-
- /* get the clock checkbox */
- GetDItem(dp, lastItem - initDev + clockOn, &controlValue, &theControl, &box);
- if ((short) *(*configHandle + 3))
- SetCtlValue(theControl, 1);
-
- /* get the "screen saver on" checkbox */
- GetDItem(dp, lastItem - initDev + screenOn, &controlValue, &theControl, &box);
- if ((short) *(*configHandle + 4))
- SetCtlValue(theControl, 1);
-
- /* get the "Show Startup Icon" checkbox */
- GetDItem(dp, lastItem - initDev + startupIcon, &controlValue, &theControl, &box);
- if ((short) *(*configHandle + 6))
- SetCtlValue(theControl, 1);
-
- /* get the "Fade To White" checkbox */
- GetDItem(dp, lastItem - initDev + fadeWhite, &controlValue, &theControl, &box);
- if ((short) *(*configHandle + 7))
- SetCtlValue(theControl, 1);
-
- /* get the "Menubar Kluge" checkbox */
- GetDItem(dp, lastItem - initDev + menuKluge, &controlValue, &theControl, &box);
- if ((short) *(*configHandle + 8))
- SetCtlValue(theControl, 1);
-
- /* get the idle time edit text item */
- GetDItem(dp, lastItem - initDev + idleMins, &controlValue, &theControl, &box);
- theLong = (long) ((short) *(*configHandle + 2));
- NumToString(theLong, theString);
- SetIText(theControl, theString);
- SelIText(dp, lastItem - initDev + idleMins, 0, 32767);
-
- /* get the refresh time edit text item */
- GetDItem(dp, lastItem - initDev + refreshSecs, &controlValue, &theControl, &box);
- theLong = (long) ((short) *(*configHandle + 5));
- NumToString(theLong, theString);
- SetIText(theControl, theString);
-
- ReleaseResource(configHandle);
- }
-
-
-
- /**********************************************************
- * BBcdev::Deactivate
- *
- * This method releases the 'PICT' resources.
- **********************************************************/
- void BBcdev::Deactivate(void)
- {
- short i;
-
- for (i = 0; i < 4; ++i)
- ReleaseResource(pictHandles[i]);
-
- inherited::Deactivate();
- }
-
-
-
- /**********************************************************
- * BBcdev::ItemHit
- *
- * This handles dialog item hits.
- **********************************************************/
- void BBcdev::ItemHit(short theItem)
- {
- ControlHandle theControl, tempControl;
- short controlValue, count;
- Rect box;
-
- GetDItem(dp, lastItem - initDev + theItem, &controlValue, &theControl, &box);
- switch (theItem) {
-
- case sleepNow:
- GlobalToLocal(&event->where);
- if (PtInRect(event->where, &smallSNRect[topLeftRect])
- && neverSleepRect != topLeftRect)
- sleepNowRect = topLeftRect;
- else if (PtInRect(event->where, &smallSNRect[topRightRect])
- && neverSleepRect != topRightRect)
- sleepNowRect = topRightRect;
- else if (PtInRect(event->where, &smallSNRect[botRightRect])
- && neverSleepRect != botRightRect)
- sleepNowRect = botRightRect;
- else if (PtInRect(event->where, &smallSNRect[botLeftRect])
- && neverSleepRect != botLeftRect)
- sleepNowRect = botLeftRect;
- else {
- SysBeep(5);
- break;
- }
-
- SetDItem(dp, lastItem - initDev + sleepNow,
- controlValue, pictHandles[sleepNowRect], &box);
- InsetRect(&box, 3, 3);
- EraseRect(&box);
- InsetRect(&box, -3, -3);
- DrawPicture(pictHandles[sleepNowRect], &box);
- break;
-
- case neverSleep:
- GlobalToLocal(&event->where);
- if (PtInRect(event->where, &smallNSRect[topLeftRect])
- && sleepNowRect != topLeftRect)
- neverSleepRect = topLeftRect;
- else if (PtInRect(event->where, &smallNSRect[topRightRect])
- && sleepNowRect != topRightRect)
- neverSleepRect = topRightRect;
- else if (PtInRect(event->where, &smallNSRect[botRightRect])
- && sleepNowRect != botRightRect)
- neverSleepRect = botRightRect;
- else if (PtInRect(event->where, &smallNSRect[botLeftRect])
- && sleepNowRect != botLeftRect)
- neverSleepRect = botLeftRect;
- else {
- SysBeep(5);
- break;
- }
-
- SetDItem(dp, lastItem - initDev + neverSleep,
- controlValue, pictHandles[neverSleepRect], &box);
- InsetRect(&box, 3, 3);
- EraseRect(&box);
- InsetRect(&box, -3, -3);
- DrawPicture(pictHandles[neverSleepRect], &box);
- break;
-
- case screenOn:
- case clockOn:
- case startupIcon:
- case fadeWhite:
- case menuKluge:
- controlValue = GetCtlValue(theControl);
- controlValue = !controlValue;
- SetCtlValue(theControl, controlValue);
- break;
-
- case remButton:
- RememberValues();
- break;
-
- default:
- break;
- }
- }
-
-
-
- /**********************************************************
- * BBcdev::Key
- *
- * This filters out invalid key presses.
- **********************************************************/
- void BBcdev::Key(short theKey)
- {
- ControlHandle theControl;
- short controlValue;
- Rect box;
- long time;
-
- if (((theKey < '0') || (theKey > '9')) && (theKey != 8) && (theKey != 13) && (theKey != 9) && ((theKey < 28) || (theKey > 31))) {
- event->what = nullEvent;
- SysBeep(5);
- }
- if (theKey == 13) {
- event->what = nullEvent;
- GetDItem(dp, lastItem - initDev + remButton, &controlValue, &theControl, &box);
- HiliteControl(theControl, 1);
- for (time = TickCount() + 15; TickCount() < time;)
- SystemTask();
- HiliteControl(theControl, 0);
- RememberValues();
- }
- }
-
-
-
- /**********************************************************
- * BBcdev::RememberValues
- *
- * This saves the information in the CNFG resource, and,
- * if the Basic Black INIT is loaded, sets the values of
- * its patch globals in memory.
- **********************************************************/
- void BBcdev::RememberValues(void)
- {
- Handle configHandle;
- ControlHandle theControl;
- short controlValue, count;
- long theLong;
- Rect box;
- Str255 theString;
- PatchGlobalsPtr pgPtr;
-
- configHandle = GetIndResource('PREF', 1); // get the first 'PREF'
-
- /* set the idle time information */
- GetDItem(dp, lastItem - initDev + idleMins, &controlValue, &theControl, &box);
- GetIText(theControl, theString);
- StringToNum(theString, &theLong);
- *(*configHandle + 2) = (short) theLong;
- if (theLong < 1 || theLong > 127) {
- Alert(128, NULL);
- SelIText(dp, lastItem - initDev + idleMins, 0, 32767);
- return;
- }
-
- /* set the refresh time information */
- GetDItem(dp, lastItem - initDev + refreshSecs, &controlValue, &theControl, &box);
- GetIText(theControl, theString);
- StringToNum(theString, &theLong);
- *(*configHandle + 5) = (short) theLong;
- if (theLong < 1 || theLong > 127) {
- Alert(128, NULL);
- SelIText(dp, lastItem - initDev + refreshSecs, 0, 32767);
- return;
- }
-
- /* set the sleep corner information */
- **configHandle = sleepNowRect;
-
- /* set the wake corner information */
- *(*configHandle + 1) = neverSleepRect;
-
- /* set the clock information */
- GetDItem(dp, lastItem - initDev + clockOn, &controlValue, &theControl, &box);
- *(*configHandle + 3) = GetCtlValue(theControl);
-
- /* set the "screen saver on" information */
- GetDItem(dp, lastItem - initDev + screenOn, &controlValue, &theControl, &box);
- *(*configHandle + 4) = GetCtlValue(theControl);
-
- /* set the "Startup Icon" information */
- GetDItem(dp, lastItem - initDev + startupIcon, &controlValue, &theControl, &box);
- *(*configHandle + 6) = GetCtlValue(theControl);
-
- /* set the "Fade To White" information */
- GetDItem(dp, lastItem - initDev + fadeWhite, &controlValue, &theControl, &box);
- *(*configHandle + 7) = GetCtlValue(theControl);
-
- /* set the "Zero Menu Bar" information */
- GetDItem(dp, lastItem - initDev + menuKluge, &controlValue, &theControl, &box);
- *(*configHandle + 8) = GetCtlValue(theControl);
-
- /* If the extension's installed, then update it's patch globals */
- if (Gestalt('BBlk', (long *) &pgPtr) == noErr) {
- pgPtr->pgMustSleep = false;
- pgPtr->pgSleepRect = (short) **configHandle;
- pgPtr->pgWakeRect = (short) *(*configHandle + 1);
- pgPtr->pgIdleTicks = (long) ((short) *(*configHandle + 2)) * 3600;
- pgPtr->pgBouncingClock = (Boolean) *(*configHandle + 3);
- pgPtr->pgMustSave = (Boolean) *(*configHandle + 4);
- pgPtr->pgRefreshTime = ((short) *(*configHandle + 5)) * 60;
- if (((short) *(*configHandle + 7)) == 0) { // Fade to black
- StuffHex(&(pgPtr->pgForePat), "\p0000000000000000");
- StuffHex(&(pgPtr->pgBackPat), "\pFFFFFFFFFFFFFFFF");
- } else { // Fade to white
- StuffHex(&(pgPtr->pgForePat), "\pFFFFFFFFFFFFFFFF");
- StuffHex(&(pgPtr->pgBackPat), "\p0000000000000000");
- }
- pgPtr->pgMenubarKluge = (Boolean) *(*configHandle + 8);
- }
-
- ChangedResource(configHandle);
- WriteResource(configHandle);
- ReleaseResource(configHandle);
- }